#pragma once

#include <lib3d/hard/VertexBuffer.h>
#include <lib3d/hard/Manager.h>
#include <HardwareDependentObject.h>
#include "Node.h"
#include <CompilerFeatures.h>

namespace liba {
namespace lib3d {
namespace node {

class Gradient : public Node, public HardwareDependentObject<hard::Manager, hard::VertexBuffer>
{
NODE_DEFINITION(Gradient)
public:
	enum Direction
	{
		LEFTGRADIENT,
		RIGHTGRADIENT,
		UPGRADIENT,
		DOWNGRADIENT
	};
	static converter::EnumPair<char, Direction> DirectionNames[];
	
	enum AlignmentType
	{
		CENTER,
		LEFT,
		RIGHT,
		TOP,
		BOTTOM
	};
	static converter::EnumPair<char, AlignmentType> AlignmentTypeNames[];
private:
	bool          _needUpdate;
	Color         _startColor, _endColor;
	float         _startTransparency, _endTransparency;
	float         _width, _height;
	AlignmentType _alignX, _alignY;
	Direction     _direction;
protected:
	virtual void on_add_hardware(hard::Manager::hardware_type * ha) LIBA_OVERRIDE;
	virtual bool on_attribute(xml::Provider * provider, const std::string & name, const std::string & value) LIBA_OVERRIDE;
public:
	static const Atom node_name;
private:
	void rebuild_gradient_plane();
	float get_x_with_align(float dx);
	float get_y_with_align(float dy);
public:
	Gradient(const Atom & name, Node * parent);
	virtual ~Gradient();
	virtual Gradient * Clone() LIBA_OVERRIDE;
	virtual void RenderToList(hard::Hardware * hardware, hard::RenderList * render_list) LIBA_OVERRIDE;
	void set_colors(const Color & startColor, const Color & endColor, float startTransparency, float endTransparency);
	void set_size(float width, float height);
	Color get_start_color() const;
	Color get_end_color() const;
	float get_start_transparency() const;
	float get_end_transparency() const;
	float get_width() const;
	float get_height() const;
};
	
}
}

namespace converter
{
	template<>
	struct ConverterTraits<char, lib3d::node::Gradient::Direction> : public ConverterTraitsEnumBase<char, lib3d::node::Gradient::Direction, lib3d::node::Gradient::DirectionNames> {};
	
	template<>
	struct ConverterTraits<char, lib3d::node::Gradient::AlignmentType> : public ConverterTraitsEnumBase<char, lib3d::node::Gradient::AlignmentType, lib3d::node::Gradient::AlignmentTypeNames> {};
}
}
